<template>
	<view style="width: 750upx; overflow: hidden;">
		
		<view class="button" v-if="isManagershow">
			<button type="primary" @click="ReleaseTask()">发布任务</button>
		</view>
		
		<view class="tabview">
			<view v-for="(item,index) in tabArray" :key="index" :class="{'active':index==current}" @click="tabClick(index)">{{item}}</view>
		</view>
		<mix-pulldown-refresh ref="mixPulldownRefresh" class="panel-content" :top="pulldownTop" @refresh="onPulldownReresh">
			<scroll-view class="panel-scroll-box" :scroll-y="true" @scrolltolower="loadMore" :style="{height: 'calc(100% - ' + pageTop + 'px)'}">
				
				<view class="uni-list">
					<view class="uni-list">
						<view class="uni-list-cell" hover-class="uni-list-cell-hover"
								v-for="(item,index) in dataList"
								:key='index'
							>
							<view class="uni-media-list" @click="gotodetail(item.id)">
								<image class="uni-media-list-logo" :src="baseURL+item.avatar"></image>
								<view class="uni-media-list-body">
									<view class="uni-media-list-text-top">{{item.title}}</view>
									<view class="uni-media-list-text-bottom"></view>
									<view class="time">
										<text>截止时间:{{item.overtime}}</text>
										<button v-if="current==3" class="updata" @click="ReleaseTask(item)" type="default" size="mini">修改</button>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				
				
				<mix-load-more :status="loadMoreStatus"></mix-load-more>
			</scroll-view>
		</mix-pulldown-refresh>
	</view>
</template>

<script>
	import mixPulldownRefresh from '@/components/mix-pulldown-refresh/mix-pulldown-refresh';
	import mixLoadMore from '@/components/mix-load-more/mix-load-more';

	export default {
		components: {
			mixLoadMore,
			mixPulldownRefresh
		},
		data() {
			return {
				baseURL:this.$API.baseURL,
				pageTop:uni.upx2px(0),
				pulldownTop:98,
				loadMoreStatus:false,
				isManagershow:false,
				
				userid:uni.getStorageSync("userid"),
				tabArray: ['全部', '未完成 ', '已完成 '],
				current: 0,
				dataList: [],
				page:1,
				row:10,
				total:1,
			};
		},
		onShow(options) {
			this.dataList=[]
			this.page=1
			this.listByUser()
		},
		onLoad(options) {
			this.isManager()
			// this.listByUser()
		},
		methods: {
			//管理员判定接口：true是管理员
			isManager(){
				var _this = this;
				uni.request({
					url:this.$API.isManager,
					method:"GET",
					data:{userid:this.userid},
					header:this.$API.get_head(),
					success: (res) => {
						if(res.data.data.isManager){
							_this.tabArray=['全部','未完成 ','已完成 ','我发起的'];
							_this.pulldownTop=230;
							_this.isManagershow=true;
						}else{
							_this.tabArray=['全部', '未完成 ','已完成'];
							_this.pulldownTop=98;
						}
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					}
				})
			},
			//任务列表
			listByUser(){
				var _this = this;
				_this.loadMoreStatus=true;
				var reqdata = {
					userid:this.userid,
					page:this.page,
					rows:this.row
				}
				if(this.current==3){
					reqdata.myStart = 0
				}else{
					reqdata.status = this.current
				}
				uni.request({
					url:this.$API.listByUser,
					method:"POST",
					data:reqdata,
					header:this.$API.get_head(),
					success: (res) => {
						_this.dataList =_this.dataList.concat(res.data.data.rows);
						_this.total = res.data.data.total
						_this.$refs.mixPulldownRefresh && _this.$refs.mixPulldownRefresh.endPulldownRefresh();
						_this.loadMoreStatus=false;
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
						_this.loadMoreStatus=false;
					}
				})
			},
			//tab 点击
			tabClick(index) {
				if (this.current != index) {
					this.current = index;
					this.dataList = [];
					this.page=1;
					this.listByUser()
				}
			},
			gotodetail(id){
				uni.navigateTo({
					url:'renwuxiangqing?id='+id
				})
			},
			//下拉刷新
			onPulldownReresh(){
				this.dataList =[]
				this.page = 1
				this.listByUser()
			},
			//上滑加载
			loadMore(){
				if(this.total != this.page){
					this.page++
					this.listByUser()
				}else{
					this.loadMoreStatus=2;
				}
			},
			//跳转任务发布
			ReleaseTask(data){
				if(data){
					e = encodeURIComponent(JSON.stringify(data))
					uni.navigateTo({
						url:'ReleaseTask?data='+data,
					})
				}else{
					uni.navigateTo({
						url:'ReleaseTask'
					})
				}
				
			}
		},
		
	}
</script>

<style lang="scss">
	.tabview{
		display: flex;
		background:#FFFFFF;
		position: relative;
		z-index: 999;
		view{
			border-bottom:10upx solid #fff;
			line-height:88upx;
			color:#333333;
			text-align: center;
			flex: 1;
			font-size:30upx;
		}
		.active{
			border-bottom:5upx solid red;
			color: red;
			font-weight: bold;
		}
	}
	
	.button{
		padding:20upx 0;
	}
	.button button{
		width:75%;
		margin:0 auto;
	}
	
	.updata{
		position:absolute;
		right:20upx;
		bottom:20upx;
	}
	
	.uni-list-cell-db{
		text-align: center;
	}
	.uni-list-cell-db image{
		width:30upx;
		height:30upx;
		vertical-align:middle;
		margin-left:10upx;
	}
	.uni-media-list-logo {
		width: 180upx;
		height: 140upx;
		/* margin-left:20upx; */
		margin-right: 20upx;
	}
	
	.uni-media-list-body {
		height: auto;
		justify-content: space-around;
	}
	.uni-media-list-body .time{
		font-size:20upx;
		color:#666;
	}
	.uni-media-list-body .time .play{
		width:50upx;
		height:50upx;
		/* float:right; */
		position:absolute;
		right:30upx;
		bottom:30upx;
	}
	.uni-media-list-text-top {
		height: 74upx;
		font-size: 28upx;
		overflow: hidden;
	}
	
	.uni-media-list-text-bottom {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
	
	.tap {
		/* border:1px solid #000000; */
		font-size:16upx;
		color: #000000;
		padding:4upx 7upx;
		margin-right:10upx;
		border-radius:10upx;
		background:#D0D0D0;
	}
	/* .tap.tapDr{
		border-color: #F43530;
		color: #F43530;
	}
	.tap.tapbu{
		border-color: #6AAFF5;
		color:  #6AAFF5;
	} */
	
	.navigator-hover{
		opacity:1;
		background:none;
	}
</style>
